package net.maku.module.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import net.maku.framework.common.utils.Result;
import net.maku.framework.security.user.SecurityUser;
import net.maku.module.entity.AgApproveEntity;
import net.maku.module.service.AgApproveService;
import net.maku.module.service.AgCategoryPermissionService;
import net.maku.module.entity.AgCategoryPermission;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统用户管理栏目(AgCategoryPermission)表控制层
 *
 * @author ChiHongYu
 * @since 2025-01-08 13:23:40
 */
@Tag(name = "系统用户管理栏目接口")
@RestController
@RequestMapping("agCategoryPermission")
public class AgCategoryPermissionController {

    @Resource
    private AgCategoryPermissionService agCategoryPermissionService;

    @Resource
    private AgApproveService agApproveService;


    @Operation(summary = "创建或修改")
    @PostMapping("createOrUpdate")
    public Result<AgCategoryPermission> createOrUpdate(@RequestBody List<AgCategoryPermission> param) {
        if (SecurityUser.getUser() == null)
            return Result.error(403, "未登录，权限认证失败");
        long executor = SecurityUser.getUser().getId();
        //System.out.println(param1);
        //List<AgCategoryPermission> param = new ArrayList<>();
        AgCategoryPermission opResult = this.agCategoryPermissionService.insertOrUpdate(param, executor);
        return Result.ok(opResult);
    }

    @Operation(summary = "根据ID查询详情")
    @GetMapping("get")
    public Result<AgCategoryPermission> get(@RequestParam("id") Integer id) {
        AgCategoryPermission agCategoryPermission = this.agCategoryPermissionService.queryById(id);
        return Result.ok(agCategoryPermission);
    }

    @Operation(summary = "根据roleId查询详情")
    @GetMapping("getByRoleId")
    public Result<AgCategoryPermission> getByRoleId(@RequestParam("sysRoleId") long sysRoleId) {
        AgCategoryPermission agCategoryPermission = this.agCategoryPermissionService.queryByRoleId(sysRoleId);
        return Result.ok(agCategoryPermission);
    }

    /**
     * 通用审核接口
     */
    @Operation(summary = "通用审核接口")
    @PostMapping("approve")
    public Result<AgCategoryPermission> approve(@RequestBody AgApproveEntity agApprove) {
        agApproveService.approve(agApprove);
        return Result.ok();
    }

    /**
     * 提交审核接口
     */
    @Operation(summary = "提交审核接口")
    @PostMapping("review")
    public Result<AgCategoryPermission> review(@RequestBody AgApproveEntity agApprove) {
        agApproveService.addApprove(agApprove.getBusinessType(), Long.valueOf(agApprove.getBusinessId()));
        return Result.ok();
    }

}
